package uploader

import "github.com/aliyun/aliyun-oss-go-sdk/oss"

type aliOss struct {
	client *oss.Client
	bucket *oss.Bucket
}

func NewOss(endPoint, accessKeyID, accessKeySecret, bucketName string) (Uploader, error) {
	c, err := oss.New(endPoint, accessKeyID, accessKeySecret)
	if err != nil {
		return nil, err
	}
	b, err := c.Bucket(bucketName)
	if err != nil {
		return nil, err
	}
	return &aliOss{
		client: c,
		bucket: b,
	}, nil
}

func (o *aliOss) Upload(target, localFile string) error {
	return o.bucket.PutObjectFromFile(target, localFile)
}
